;************************************ ;Project title: Temperature Sensor * ;Version 1: 1.0 * ;Written By: MSH * ;Dated: 20/02/06 * ;For PIC: PIC16F84A * ;Clock Freq: 8.0MHz * ;************************************ ; PROGRAM FUNCTION:___________________________ ;_____________________________________________ List P=16F84A include ;============ ; Declarations: porta equ 05 portb equ 06 serial_data equ 0C bit_count equ 0D post25 equ 0E hex_value equ 0F mark64 equ 10 post12 equ 11 #define clk porta,2 #define dout porta,3 #define cs porta,4 org 0 goto Start ;============ ; Subroutines: Init clrf porta ; resets Port A and B. clrf portb ; bsf STATUS,5 ; selects bank 1 movlw b'01000' ; RA0-RA1 = LEDs 1 & 2, RA2 = ADC_CLK, movwf TRISA ; RA3 = ADC_Dout, RA4 = ADC_CS. movlw b'00000000' ; RB0-RB7 = LEDs 3-7. movwf TRISB ; the LEDs. movlw b'00000111' ; TMR0 prescaled by 256 movwf OPTION_REG ; pull ups disabled. bcf STATUS, 5 ; Selects bank 0 call reset12 ; resets post12. call reset25 ; resets post25. call reset64 ; resets mark64. movlw b'00000000' ; disables all interrupts. movwf INTCON ; return ; returns from subroutine. adc_dataout bcf cs ; enables adc chip (U2). clrf serial_data ; Clears file for storing the ADC's 8bit output. movlw d'8' ; places the decimal No '8' into the file movwf bit_count ; register bit_count. loop btfsc dout ; is the bit on ADC D_out pin a 0. bsf STATUS,C ; if no sets carry flag. btfss dout ; is the bit on ADC D-out pin a 1. bcf STATUS,C ; if yes clears carry flag. bsf clk ; creates a high clock on the ADC clk pin. nop ; creates a 1/2000000th of a second delay. bcf clk ; creates a low clock on the ADC clk pin. rlf serial_data,f ; places contents of the carry flag into serial_data. decfsz bit_count,f ; have all 8 bits been recieved. goto loop return ; returns from subroutine. bin2hex movlw h'00' ; clears contents of working reg. btfsc serial_data,7 ; tests bit 7 of file register serial_data. addlw h'7F' ; adds the hexidecimal No'7F' to working reg. btfsc serial_data,6 ; tests bit 6 of file register serial_data. addlw h'3F' ; adds the hexidecimal No'3F' to working reg. btfsc serial_data,5 ; tests bit 5 of file register serial_data. addlw h'1F' ; adds the hexidecimal No'1F' to working reg. btfsc serial_data,4 ; tests bit 4 of file register serial_data. addlw h'0F' ; adds the hexidecimal No'0F' to working reg. btfsc serial_data,3 ; tests bit 3 of file register serial_data. addlw h'08' ; adds the hexidecimal No'08' to working reg. btfsc serial_data,2 ; tests bit 2 of file register serial_data. addlw h'04' ; adds the hexidecimal No'04' to working reg. btfsc serial_data,1 ; tests bit 1 of file register serial_data. addlw h'02' ; adds the hexidecimal No'02' to working reg. btfsc serial_data,0 ; tests bit 0 of file register serial_data. addlw h'01' ; adds the hexidecimal No'01' to working reg. movwf hex_value ; moves value in working reg into file ; register 'hex_value'. return ; returns from subroutine. reset25 movlw d'25' ; moves the decimal number '25' into the movwf post25 ; files register post25. return ; returns from subroutine. reset64 movlw d'64' ; moves the decimal number '64' into the movwf mark64 ; files register post64. return ; returns from subroutine. reset12 movlw d'12' ; moves the decimal number '12' into the movwf post12 ; files register post12. return ; returns from subroutine. tenthsec clrf TMR0 ; resets TMR0. tenthsec1 movfw mark64 ; takes the number out of mark64. subwf TMR0,w ; subtracts this number from the number ; in TMR0, leaving the result in the ; working register (and leaving TMR0 unchanged) btfss STATUS,Z ; tests the zero flag - skip if set i.e. if the ; result is zero it will skip the next instruction. goto tenthsec1 ; loops to tenthsec1. decfsz post12,f ; decrements post12, and skips the next ; instruction if the result is zero. goto tenthsec ; if the result isn't zero, it loops back ; to 'tenthsec1'. call reset12 ; resets post12. return ; returns from subroutine. return ; returns from subroutine. ;============================================ ; Program Start: Start call Init ; sets up everything. main call adc_dataout ; movfw serial_data ; call bin2hex ; creates a hexidecimal value from serial data. btfss serial_data,7 ; goto bit7c goto bit7s bit7c btfss serial_data,6 ; goto bit7c6c goto bit7c6s bit7s btfss serial_data,6 ; goto bit7s6c goto bit7s6s bit7c6c btfss serial_data,5 ; goto bit7c6c5c goto bit7c6c5s bit7c6s btfss serial_data,5 goto bit7c6s5c goto bit7c6s5s bit7s6c btfss serial_data,5 goto bit7s6c5c goto bit7s6c5s bit7s6s btfss serial_data,5 goto bit7s6s5c goto bit7s6s5s bit7c6c5c btfss serial_data,4 ; goto bit7c6c5c4c goto bit7c6c5c4s bit7c6c5s btfss serial_data,4 ; goto bit7c6c5s4c goto bit7c6c5s4s bit7c6s5c btfss serial_data,4 ; goto bit7c6s5c4c goto bit7c6s5c4s bit7c6s5s btfss serial_data,4 ; goto bit7c6s5s4c goto bit7c6s5s4s bit7s6c5c btfss serial_data,4 ; goto bit7s6c5c4c goto bit7s6c5c4s bit7s6c5s btfss serial_data,4 ; goto bit7s6c5s4c goto bit7s6c5s4s bit7s6s5c btfss serial_data,4 ; goto bit7s6s5c4c goto bit7s6s5c4s bit7s6s5s btfss serial_data,4 ; goto bit7s6s5s4c goto bit7s6s5s4s bit7c6c5c4c btfss serial_data,3 ; goto LED1 goto bit7c6c5c4c3s bit7c6c5c4s btfss serial_data,3 ; goto LED1A goto bit7c6c5c4s3s bit7c6c5s4c btfss serial_data,3 ; goto LED2 goto LED2A bit7c6c5s4s btfss serial_data,3 ; goto bit7c6c5s4s3c goto LED3 bit7c6s5c4c btfss serial_data,3 ; goto bit7c6s5c4c3c goto bit7c6s5c4c3s bit7c6s5c4s btfss serial_data,3 ; goto LED4 ; goto bit7c6s5c4s3s ; bit7c6s5s4c btfss serial_data,3 ; goto LED4A ; goto LED5 ; bit7c6s5s4s btfss serial_data,3 ; goto bit7c6s5s4s3c ; goto LED5A ; bit7s6c5c4c btfss serial_data,3 ; goto bit7s6c5c4c3c goto LED6 bit7s6c5c4s btfss serial_data,3 ; goto LED6A goto bit7s6c5c4s3s bit7s6c5s4c btfss serial_data,3 ; goto LED7 goto bit7s6c5s4c3s bit7s6c5s4s btfss serial_data,3 ; goto bit7s6c5s4s3c goto LED8 bit7s6s5c4c btfss serial_data,3 ; goto bit7s6s5c4c3c goto LED8A bit7s6s5c4s btfss serial_data,3 ; goto LED9 goto bit7s6s5c4s3s bit7s6s5s4c btfss serial_data,3 ; goto LED9A goto bit7s6s5s4c3s bit7s6s5s4s btfss serial_data,3 ; goto bit7s6s5s4s3c goto LED10A bit7c6c5c4c3s btfss serial_data,2 ; goto LED1 goto bit7c6c5c4c3s2s ; LED1/LED1A bit7c6c5c4s3s btfss serial_data,2 ; goto bit7c6c5c4s3s2c ; LED1A/LED2 goto LED2 bit7c6c5s4s3c btfss serial_data,2 ; goto LED2A goto LED3 bit7c6s5c4c3c btfss serial_data,2 ; goto bit7c6s5c4c3c2c ; LED3/LED3A goto LED3A bit7c6s5c4c3s btfss serial_data,2 ; goto LED3A goto bit7c6s5c4c3s2s ; LED3A/LED4 bit7c6s5c4s3s btfss serial_data,2 ; goto LED4 goto LED4A bit7c6s5s4s3c btfss serial_data,2 ; goto LED5 goto bit7c6s5s4s3c2s ; LED5/LED5A bit7s6c5c4c3c btfss serial_data,2 ; goto bit7s6c5c4c3c2c ; LED5A/LED6 goto LED6 bit7s6c5c4s3s btfss serial_data,2 ; goto LED6A goto LED7 bit7s6c5s4c3s btfss serial_data,2 ; goto bit7s6c5s4c3s2c ; LED7/LED7A goto LED7A bit7s6c5s4s3c btfss serial_data,2 ; goto LED7A goto bit7s6c5s4s3c2s ; LED7A/LED8 bit7s6s5c4c3c btfss serial_data,2 ; goto LED8 goto LED8A bit7s6s5c4s3s btfss serial_data,2 ; goto LED9 goto bit7s6s5c4s3s2s ; LED9/LED9A bit7s6s5s4c3s btfss serial_data,2 ; goto bit7s6s5s4c3s2c ; LED9A/LED10 goto LED10 bit7s6s5s4s3c btfss serial_data,2 ; goto LED10 goto LED10A bit7c6c5c4c3s2s btfss serial_data,1 ; goto LED1 goto LED1A bit7c6c5c4s3s2c btfss serial_data,1 ; goto LED1A goto LED2 bit7c6s5c4c3c2c btfss serial_data,1 ; goto LED3 goto LED3A bit7c6s5c4c3s2s btfss serial_data,1 ; goto LED3A goto LED4 bit7c6s5s4s3c2s btfss serial_data,1 ; goto LED5 goto LED5A bit7s6c5c4c3c2c btfss serial_data,1 ; goto LED5A goto LED6 bit7s6c5s4c3s2c btfss serial_data,1 ; goto LED7 goto LED7A bit7s6c5s4s3c2s btfss serial_data,1 ; goto LED7A goto LED8 bit7s6s5c4s3s2s btfss serial_data,1 ; goto LED9 goto LED9A bit7s6s5s4c3s2c btfss serial_data,1 ; goto LED9A goto LED10 LED1 movlw b'00000001' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00000000' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED1 ; call reset25 ; resets post25. goto main ; LED1A movlw b'00000001' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED1A ; call reset25 ; resets post25. goto main ; LED2 movlw b'00000011' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00000001' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED2 ; call reset25 ; reset post25. goto main ; LED2A movlw b'00000011' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED2A ; call reset25 ; resets post25. goto main ; LED3 movlw b'00000111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00000011' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED3 ; call reset25 ; reset post25. goto main ; LED3A movlw b'00000111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED3A ; call reset25 ; resets post25. goto main ; LED4 movlw b'00001111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00000111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED4 ; call reset25 ; reset post25. goto main ; LED4A movlw b'00001111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED4A ; call reset25 ; resets post25. goto main ; LED5 movlw b'00011111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00001111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED5 ; call reset25 ; reset post25. goto main ; LED5A movlw b'00011111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED5A ; call reset25 ; resets post25. goto main ; LED6 movlw b'00111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00011111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED6 ; call reset25 ; reset post25. goto main ; LED6A movlw b'00111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED6A ; call reset25 ; resets post25. goto main ; LED7 movlw b'01111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'00111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED7 ; call reset25 ; reset post25. goto main ; LED7A movlw b'01111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED7A ; call reset25 ; resets post25. goto main ; LED8 movlw b'11111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. movlw b'01111111' ; movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED8 ; call reset25 ; reset post25. goto main ; LED8A movlw b'11111111' ; switches LEDs 1-8 on movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED8A ; call reset25 ; resets post25. goto main ; LED9 movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; bsf porta,0 ; switches LED9 on. LED 10 is off. call tenthsec ; creates 1/10th second delay. movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; clrf porta ; resets porta. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED9 ; call reset25 ; reset post25. goto main ; LED9A movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; bsf porta,0 ; switches LED9 on. LED 10 is off. call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED9A ; call reset25 ; resets post25. goto main ; LED10 movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; movlw b'00011' ; switches LEDs 9 & 10 on. movwf porta ; call tenthsec ; creates 1/10th second delay. movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; bcf porta,1 ; switches LED9 on. LED 10 is off. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED10 ; call reset25 ; reset post25. goto main ; LED10A movlw b'11111111' ; switches LEDs 1-8 on. movwf portb ; movlw b'00011' ; switches LEDs 9 & 10 on. movwf porta ; call tenthsec ; creates 1/10th second delay. call tenthsec ; creates 1/10th second delay. decfsz post25 ; goto LED10A ; call reset25 ; resets post25. goto main ; goto main ; loops to main. END ; Appendix A: LED Allocation. ; ; ;==================================================== ;8 bit coversion. ; ;CALL LED1 = 0 - 13 00000000 - 00001101 ;CALL LED1A = 13 - 26 00001101 - 00011010 ;CALL LED2 = 26 - 39 00011010 - 00100111 ;CALL LED2A = 39 - 52 00100111 - 00110100 ;CALL LED3 = 52 - 65 00110100 - 01000001 ;CALL LED3A = 65 - 78 01000001 - 01001110 ;CALL LED4 = 78 - 91 01001110 - 01011011 ;CALL LED4A = 91 - 104 01011011 - 01101000 ;CALL LED5 = 104 - 117 01101000 - 01110101 ;CALL LED5A = 117 - 130 01110101 - 10000010 ;CALL LED6 = 130 - 143 10000010 - 10001111 ;CALL LED6A = 143 - 156 10001111 - 10011100 ;CALL LED7 = 156 - 169 10011100 - 10101001 ;CALL LED7A = 169 - 182 10101001 - 10110110 ;CALL LED8 = 182 - 195 10110110 - 11000011 ;CALL LED8A = 195 - 208 11000011 - 11010000 ;CALL LED9 = 208 - 221 11010000 - 11011101 ;CALL LED9A = 221 - 234 11011101 - 11101010 ;CALL LED10 = 234 - 245 11101010 - 11110101 ;CALL LED10A = 245 - 255 11110101 - 11111111 ; ;====================================================